
#ifndef _QUEUE_THREAD_H_INCLUDE_
#define _QUEUE_THREAD_H_INCLUDE_


#include <Windows.h>
#include <list>
using namespace std;

class MQueueThread;

class MQueueThreadInfo
{
public:
	MQueueThread	*m_lpThread;
	void	*m_lpParam;
};

class MQueueParam
{
public:
	ULONGLONG	m_dwParam1;
	ULONGLONG	m_dwParam2;
};

class MQueueParam;

#define QUEUE_ADD	2
#define	QUEUE_GET	3
#define	QUEUE_COUNT	4

/////////////////////////////////////////////////////////////////////////////
//

class MQueueThread
{
public:
	MQueueThread();
	virtual ~MQueueThread();

private:
	HANDLE	m_lpThread;
	MQueueThreadInfo	m_ThreadInfo;
	CRITICAL_SECTION	m_CriticalSection;
	HANDLE		m_hEndEvent;
	HANDLE		m_hQueue;
	list<MQueueParam*>		m_Queue;
	UINT		m_dwElaps;
	BOOL		m_bThreadExec;

private:
	static UINT WorkerThread(void *lpParam);
	UINT Run();
protected:
	void SetTimer(UINT uElapse);
public:
	BOOL StartThread(void *lpParam);
	void EndThread();
	int ThreadQueue(DWORD dwType, ULONGLONG dwParam1=0, ULONGLONG dwParam2=0);
	DWORD CheckEndRequest();

protected:
	virtual BOOL InitThread(void *lpParam);
	virtual void ExitThread();
	virtual int OnAddQueue(MQueueParam *lpQueueParam);
	virtual void ProcessQueue(MQueueParam *lpQueueParam);
	virtual void ProcessTimeout();
};

/////////////////////////////////////////////////////////////////////////////

#endif